<?php
namespace Home\Controller;
use Think\Controller;
class TestController extends Controller {

	public $signPackage;
	/**
	 * 初始化
	 */
	public function __construct() {
		parent::__construct();
		Vendor('Wechat.Wechats');
		$option = array(
			'corpid'=>C('CORPID'),
			'secret'=>C('SECRET'),
		);
		$wechats = new \Wechats($option);
		$access = $wechats->getAccesstoken();
		$jsdk = $wechats->getJsapiticket();
		$this->signPackage = $wechats->getSignPackage();                                                                                                                               
	}

	public function index() {
		$key  = I('get.searchkey','','strip_tags');
		$nickname = I('get.nickname','','strip_tags');
		if(!empty($nickname)) {
			$wheren['nickname'] = array('like','%'.$key.'%');
		}
		$address = I('get.address','','strip_tags');
		if(!empty($address)) {
			$wheren['address'] = array('like','%'.$key.'%');
		}
		$mobile = I('get.mobile','','strip_tags');
		if(!empty($mobile)) {
			$wheren['mobile'] = array('like','%'.$key.'%');
		}
		$qq = I('get.qq','','strip_tags');
		if(!empty($qq)) {
			$wheren['qq'] = array('like','%'.$key.'%');
		}
		$cs = I('get.cs','','strip_tags');
		if(!empty($cs)) {
			$wheren['cs'] = array('like','%'.$key.'%');
		}
		$qg = I('get.qg','','strip_tags');
		if(!empty($qg)) {
			$wheren['qg'] = array('like','%'.$key.'%');
		}
		$company = I('get.company','','strip_tags');
		if(!empty($company)) {
			$wheren['company'] = array('like','%'.$key.'%');
		}

		$province = I('get.province','','strip_tags');
		if(!empty($province)) {
			$wheren['province'] = array('like','%'.$key.'%');
		}

		$city = I('get.city','','strip_tags');
		if(!empty($city)) {
			$wheren['city'] = array('like','%'.$key.'%');
		}

		if(empty($nickname) && empty($address) && empty($mobile) && empty($qq) && empty($cs) && empty($qg) && empty($company) && empty($province) && empty($city)) {
			$wheren['nickname'] = array('like','%'.$key.'%');
		} else {
			$wheren['_logic'] = 'or';
		}

		$getprovince = I('get.province','','strip_tags');
		if(!empty($getprovince)) {
			if($getprovince == '全部') {
				$_SESSION['province'] = '';
			} else {
				$_SESSION['province'] = $getprovince;
			}
		}
		$where['_complex'] = $wheren;
		if(!empty($_SESSION['province'])) {
			$where['province'] = $_SESSION['province'];
		}

		//$where['id'] = array('NEQ',$this->userinfo['id']);
		$list = D('Admin/address')->hselect($where);
		$this->assign('list',$list);
		$this->assign('listzm',$listzm);

		/**jssdk***/
		$signPackage = $this->signPackage;
		$signPackage['title'] = "苗木通讯录";
		$signPackage['link'] = 'http://'.C('DOMAIN').U('Index/index');
		$signPackage['desc'] = "众里寻他千百度，苗友尽在通讯录，苗商驰骋天地间，买卖沟通更方便。";
		$signPackage['imgUrl'] = 'http://zhumeng777.com/Uploads/2016-09-18/57de84aca6a35.jpg';
		$this->assign('signPackage',$signPackage);
		/****/
		$this->display();
	}

	public function info() {
		$id = I('get.id','','intval');

		$info = D('address')->find($id);

		/**jssdk***/
		$signPackage = $this->signPackage;
		$signPackage['title'] = "苗木通讯录：".$info['nickname'];
		$signPackage['link'] = 'http://'.C('DOMAIN').U('Index/info',array('id'=>$info['id']));
		$signPackage['desc'] = "众里寻他千百度，苗友尽在通讯录，苗商驰骋天地间，买卖沟通更方便。";
		$signPackage['imgUrl'] = $info['headimgurl'];
		$this->assign('signPackage',$signPackage);
		/****/

		if(!empty($info['mobile'])) {
			$mobilearr = json_decode($info['mobile'],true);
			$info['mobilearr'] = $mobilearr;
			$this->assign('mobilearr',$mobilearr);
		}

		if(!empty($info['photo'])) {
			$info['photos'] = explode('|',$info['photo']);
		}
		$this->assign('photoarr',$info['photos']);

		$this->assign('info',$info);
		/*
		$mans = explode(',',$this->userinfo['mans']);
		$this->assign('mans',$mans);
		*/
		$this->display();
	}

	public function test() {
		echo headimgsize('http://wx.qlogo.cn/mmopen/rhl2MLYibFkfkR4I0ZJjwXEuFIISgDAicMibCk7sS7vmshw9T0oicB1IrjHcicEVwVcuTRAwZe8I0EB87sOyMD5hsvc4OgcsS6lvU/0',64);
	}

	public function img() {
		$image = new \Think\Image(); 
		$image->open('./img/1.png');
		// 按照原图的比例生成一个最大为150*150的缩略图并保存为thumb.jpg
		$image->thumb(650, 650)->save('./img/11.png');
	}

}
